#include <SLCD.h>
#include <AFSoftSerial.h>
//Pin 2 is output. 
AFSoftSerial mySerial =  AFSoftSerial(10, 9);
int incomingByte = 0;
char buffer1[17] = "welcome........!";
char buffer2[17] = "Roybot1         ";

void setup()  {
  //pinMode(13, OUTPUT);
  Serial.begin(9600);
  //Serial.println("Goodnight moon!");
  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  backlightOn();
  Serial.print("Hi hooooo");

}

void loop()                     // run over and over again
{
   Serial.print("Hi hooooo");
  int i;
  if (Serial.available() > 0) {
    // read the incoming byte:

    for (i = 0; i < 33; i = i + 1) {
      if (i<16){
        buffer1[i] = Serial.read();
      }      
      if (i>16){
        buffer2[i-17] = Serial.read();
      }

      // say what you got:

      // Serial.println(incomingByte, BYTE);
    }

  }


char mask;
 for (mask = 0; mask<12; mask++) {
  selectLineOne();
  delay(100);
  mySerial.print(buffer1);
 }
  delay(100);
  selectLineTwo();
  delay(100);
  mySerial.print(buffer2);
  delay(100);
  /*
  if(i=31){
   selectLineTwo();
   delay(100);
   mySerial.print(buffer2);
   delay(100);
   i=0;
   
   }*/
}

void selectLineOne(){  //puts the cursor at line 0 char 0.
  mySerial.print(0xFE, BYTE);   //command flag
  mySerial.print(128, BYTE);    //position
}
void selectLineTwo(){  //puts the cursor at line 0 char 0.
  mySerial.print(0xFE, BYTE);   //command flag
  mySerial.print(192, BYTE);    //position
}
void clearLCD(){
  mySerial.print(0xFE, BYTE);   //command flag
  mySerial.print(0x01, BYTE);   //clear command.
}
void backlightOn(){  //turns on the backlight
  mySerial.print(0x7C, BYTE);   //command flag for backlight stuff
  mySerial.print(157, BYTE);    //light level.
}
void backlightOff(){  //turns off the backlight
  mySerial.print(0x7C, BYTE);   //command flag for backlight stuff
  mySerial.print(128, BYTE);     //light level for off.
}
void serCommand(){   //a general function to call the command flag for issuing all other commands   
  mySerial.print(0xFE, BYTE);
}
